package me.a01myfunction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Function;

public class FunctionDemo2 {
    public static void main(String[] args) {
        //需求：把集合中的"1","2","3","4"变成int类型
        //先创建集合并添加数据
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "1", "2", "3", "4");

        //变成int 类型
        //常规方式：
        /*list.stream().map(new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                int i = Integer.parseInt(s);
                return i;
            }
        }).forEach(s -> System.out.println(s));*/

        //方法引用
        list.stream().map(Integer::parseInt).forEach(s -> System.out.println(s));
    }
}
